import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  // {
  //   path: '/',
  //   component: Layout,
  //   redirect: '/dashboard',
  //   // meta: { title: '数据展示', icon: 'data_show', 'modulePath': 'info_show' },
  //   children: [{
  //     path: 'dashboard',
  //     name: 'Dashboard',
  //     component: () => import('@/views/dashboard/index'),
  //     // meta: { title: '数据展示', icon: 'dashboard', affix: true }
  //     meta: { title: '数据展示', icon: 'data_show', 'modulePath': 'info_show' }
  //   }]
  // },
  {
    path: '/',
    component: Layout,
    redirect: '/device-monitor',
    meta: { 'modulePath': 'device_manage', title: '设备监控', icon: 'warehouse-stock' },
    children: [
      {
        path: 'device-monitor',
        name: 'DeviceMonitor',
        component: () => import('@/views/deviceMonitor/index'),
        meta: { 'modulePath': 'device_manage', title: '设备监控', icon: 'warehouse-stock' }
      }
    ]
  },
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/login', hidden: true }
  // {
  //   path: '/404',
  //   component: () => import('@/views/404'),
  //   hidden: true
  // },
  // // 404 page must be placed at the end !!!
  // { path: '*', redirect: '/404', hidden: true }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [

  {
    path: '/a',
    component: Layout,
    meta: { title: '信息查询', icon: 'info_query', 'modulePath': 'info_query' },
    children: [
      {
        path: 'info',
        name: 'Info',
        component: () => import('@/views/info/index'),
        meta: { title: '信息查询', icon: 'info_query', 'modulePath': 'info_query' }
      }
    ]
  },
  {
    path: '/b',
    component: Layout,
    meta: { 'modulePath': 'statistics', title: '综合统计', icon: 'statistics' },
    children: [
      {
        path: 'statistics',
        name: 'Statistics',
        component: () => import('@/views/statistics/index'),
        meta: { 'modulePath': 'statistics', title: '综合统计', icon: 'statistics' }
      }
    ]
  },
  {
    path: '/c',
    component: Layout,
    meta: { 'modulePath': 'purchase_manage', title: '收货管理', icon: 'purchase' },
    children: [
      {
        path: 'purchase-order',
        name: 'PurchaseOrder',
        component: () => import('@/views/purchase-order/index'),
        meta: { 'modulePath': 'purchase_manage', title: '收货管理', icon: 'purchase' }
      }
    ]
  },
  {
    path: '/warehousing',
    component: Layout,
    redirect: '/warehousing/batch',
    name: 'Warehousing',
    meta: { 'modulePath': 'in_manage', title: '入库管理', icon: 'warehousing' },
    children: [
      {
        path: 'batch',
        name: 'Batch',
        component: () => import('@/views/warehousing/batch/index'),
        meta: { 'modulePath': 'batch_manage', title: '批次管理', icon: '' }
      },
      {
        path: 'label-issue',
        name: 'LabelIssue',
        component: () => import('@/views/warehousing/label-issue/index'),
        meta: { 'modulePath': 'label_issue', title: '标签发行', icon: '' }
      },
      {
        path: 'warehouse-in',
        name: 'WarehouseIn',
        component: () => import('@/views/warehousing/warehouse-in/index'),
        meta: { 'modulePath': 'in_inManage', title: '入库管理', icon: '' }
      }
    ]
  },
  {
    path: '/d',
    component: Layout,
    meta: { 'modulePath': 'out_manage', title: '出库管理', icon: 'warehouse-ex' },
    children: [
      {
        path: 'warehouse-ex',
        name: 'WarehousingEx',
        component: () => import('@/views/warehouse-ex/index'),
        meta: { 'modulePath': 'out_manage', title: '出库管理', icon: 'warehouse-ex' }
      }
    ]
  },
  {
    path: '/e',
    component: Layout,
    meta: { 'modulePath': 'stock_manage', title: '库存管理', icon: 'warehouse-stock' },
    children: [
      {
        path: 'warehouse-stock',
        name: 'WarehousingStock',
        component: () => import('@/views/warehouse-stock/index'),
        meta: { 'modulePath': 'stock_manage', title: '库存管理', icon: 'warehouse-stock' }
      }
    ]
  },
  {
    path: '/f',
    component: Layout,
    meta: { 'modulePath': 'inventory_manage', title: '库存数据', icon: 'warehouse-stock' },
    children: [
      {
        path: 'inventory-data',
        name: 'InventoryData',
        component: () => import('@/views/inventoryData/index'),
        meta: { 'modulePath': 'inventory_manage', title: '库存数据', icon: 'warehouse-stock' }
      }
    ]
  },
  {
    path: '/g',
    component: Layout,
    meta: { 'modulePath': 'warning_manage', title: '预警记录', icon: 'warehouse-stock' },
    children: [
      {
        path: 'warning-record',
        name: 'WarningRecord',
        component: () => import('@/views/warningRecord/index'),
        meta: { 'modulePath': 'warning_manage', title: '预警记录', icon: 'warehouse-stock' }
      }
    ]
  },
  // {
  //   path: '/h',
  //   component: Layout,
  //   meta: { 'modulePath': 'device_manage', title: '设备监控', icon: 'warehouse-stock' },
  //   children: [
  //     {
  //       path: 'device-monitor',
  //       name: 'DeviceMonitor',
  //       component: () => import('@/views/deviceMonitor/index'),
  //       meta: { 'modulePath': 'device_manage', title: '设备监控', icon: 'warehouse-stock' }
  //     }
  //   ]
  // },
  {
    path: '/i',
    component: Layout,
    meta: { 'modulePath': 'custom_manage', title: '客户管理', icon: 'warehouse-stock' },
    children: [
      {
        path: 'custom-page',
        name: 'CustomPage',
        component: () => import('@/views/customPage/index'),
        meta: { 'modulePath': 'custom_manage', title: '客户管理', icon: 'warehouse-stock' }
      }
    ]
  },
  {
    path: '/j',
    component: Layout,
    meta: { 'modulePath': 'inventorymake_manage', title: '盘库管理', icon: 'warehouse-stock' },
    children: [
      {
        path: 'inventory-make',
        name: 'InventoryMake',
        component: () => import('@/views/inventoryMake/index'),
        meta: { 'modulePath': 'inventorymake_manage', title: '盘库管理', icon: 'warehouse-stock' }
      }
    ]
  },
  {
    path: '/k',
    component: Layout,
    meta: { 'modulePath': 'check_manage', title: '盘点管理', icon: 'inventory-manage' },
    children: [
      {
        path: 'inventory-manage',
        name: 'InventoryManage',
        component: () => import('@/views/inventory-manage/inventory-manage/index'),
        meta: { 'modulePath': 'check_manage', title: '盘点管理', icon: 'inventory-manage' }
      }
    ]
  },
  {
    path: '/basic',
    component: Layout,
    redirect: '/basic/warehouse-manage',
    name: 'Basic',
    meta: { 'modulePath': 'base_manage', title: '基础设置', icon: 'setting' },
    children: [
      {
        path: 'warehouse-manage',
        name: 'WarehousingManage',
        component: () => import('@/views/basic/warehouse-manage/index'),
        meta: { 'modulePath': 'base_manage_query', title: '仓库管理', icon: '' }
      },
      {
        path: 'equipment',
        name: 'Equipment',
        component: () => import('@/views/basic/equipment/index'),
        meta: { 'modulePath': 'base_manage_type', title: '器材分类', icon: '' }
      },
      {
        path: 'warning-setting',
        name: 'WarningSetting',
        component: () => import('@/views/basic/warning-setting/index'),
        meta: { 'modulePath': 'base_manage_set', title: '预警设置', icon: '' }
      }
    ]
  },
  {
    path: '/system',
    component: Layout,
    redirect: '/system/role-manage',
    name: 'System',
    meta: { 'modulePath': 'sys_manage', title: '系统管理', icon: 'system' },
    children: [
      {
        path: 'role-manage',
        name: 'RoleManage',
        component: () => import('@/views/system/role-manage/index'),
        meta: { 'modulePath': 'sys_manage_role', title: '角色管理', icon: '' }
      },
      {
        path: 'user-manage',
        name: 'UserManage',
        component: () => import('@/views/system/user-manage/index'),
        meta: { 'modulePath': 'sys_manage_user', title: '用户管理', icon: '' }
      },
      {
        path: 'log-manage',
        name: 'LogManage',
        component: () => import('@/views/system/log-manage/index'),
        meta: { 'modulePath': 'sys_manage_log', title: '日志管理', icon: '' }
      },
      {
        path: 'historical-news',
        name: 'HistoricalNews',
        component: () => import('@/views/system/historical-news/index'),
        meta: { 'modulePath': 'sys_manage_history_log', title: '历史消息', icon: '' }
      }
    ]
  }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
